<template>
  <Card :dis-hover="true">
    <p slot="title">{{project.Name}}</p>
    <base-table :data="data" :columns="columns" @add="addHandler" 
    @update="updateHandler" @check="checkHandler" @approve="approveHandler"
    @delete="deleteHandler" ck></base-table>
    <Modal></Modal>
  </Card>
</template>

<script>
import moment from 'moment';
import BaseTable from '@c/table/table';
import { newApiParams } from '@/common/utils';
export default {
  name: 'BudgetList',
  components: {
    BaseTable
  },
  data () {
    return {
      data: [],
      columns: [
        {
          title: '排序',
          type: 'index'
        },
        {
          title: '用途',
          key: 'Name'
        },
        {
          title: '预算',
          render: (h, { row }) => {
            return h('span', {}, `￥${row.Budget}`);
          }
        },
        {
          title: '实际使用',
          render: (h, { row }) => {
            return h('span', {}, `￥${row.Used}`);
          }
        },
        {
          title: '说明',
          key: 'Remark'
        }
      ],
      udata: [],
      uColumns: []
    };
  },
  computed: {
    project () {
      return this.$route.params.project; 
    }
  },
  methods: {
    addHandler () {},
    updateHandler () {},
    checkHandler (rows) {
      if (Array.isArray(rows) && rows.length === 1) {
        this.$router.push({ name: '预算使用情况', params: { budget: rows[0], editorable: false, type: 1 } });
      } else {
        this.$Message.warning('请选择一条数据操作！');
      }
    },
    approveHandler () {},
    deleteHandler () {},
    getAll () {
      let params = newApiParams();
      params.query.ProjectId = this.project.Id;
      this.$api.QueryBudgetByProject(params).then((res) => {
        if (Array.isArray(res.Data) && res.Data.length > 0) {
          this.data = res.Data;
        }
      }).catch((err) => {
        if (err) {
          this.$Message.error(err);
        }
      });
    }
  },
  mounted () {
    if (!this.project) {
      this.$Message.warning('参数异常！');
      this.$router.push({ name: '已启动项目' });
    } else {
      this.getAll();
    }
  }
};
</script>

<style scoped>

</style>